package com.yidu.logisticssystem.controller;

import com.yidu.logisticssystem.entity.LogisticsMap;
import com.yidu.logisticssystem.entity.LogisticsWaybill;
import com.yidu.logisticssystem.entity.vo.WaybillVo;
import com.yidu.logisticssystem.service.LogisticsMapService;
import com.yidu.logisticssystem.service.LogisticsWaybillService;
import com.yidu.logisticssystem.utils.BaseMessage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * 货运单(LogisticsWaybill)表控制层
 *
 * @author makejava
 * @since 2021-03-08 16:46:58
 */
@Api(tags= "货运单接口")
@RestController
@RequestMapping("logisticsWaybill")
public class LogisticsWaybillController {
    /**
     * 服务对象
     */
    @Resource
    private LogisticsWaybillService logisticsWaybillService;
    @Resource
    private LogisticsMapService mapService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public LogisticsWaybill selectOne(Integer id) {
        return this.logisticsWaybillService.queryById(id);
    }


    /**
     *  添加货运订单
     * @param vo
     * @return 改变行数
     */
    @ApiOperation(value = "添加货运订单",notes = "返回改变行数")
    @PostMapping("add")
    public BaseMessage insert(WaybillVo vo, HttpServletRequest request){
        int rows=logisticsWaybillService.insert(vo,request);
        return rows>0?BaseMessage.succes():BaseMessage.fail();
    }

    @PostMapping("findWayNum")
    public BaseMessage findWayNum(LogisticsWaybill waybill){
        LogisticsWaybill bill=logisticsWaybillService.way_num(waybill.getWayNum());
        //发货地址
        String toarea=bill.getWaySendarea();
        String []tomap=toarea.split(",");
        String tomapid=tomap[0];
        //收货地址
        String goarea=bill.getWayConsignarea();
        String []gomap=goarea.split(",");
        String gomapid=gomap[0];
        //根据地区id查询经纬度
        LogisticsMap map=mapService.queryById(tomapid);
        LogisticsMap maps=mapService.queryById(gomapid);
        map.setTomapEast(maps.getMapEast());
        map.setTomapNorth(maps.getMapNorth());
        return BaseMessage.succes(map);
    }
}
